# coding: utf-8
from constants import apb
from requests import Response
from utils.logger_handle import logger


class DouPageLogin:
    """fat后台登录"""
    @staticmethod
    def login(account: str, psd: str, accountType: str = "mobile", isAdmin: bool = False) -> None:
        """登录
        Args:
            account (str): 用户名
            psd (str): 密码
            accountType (str, optional): 登录类型. Defaults to "mobile"
            isAdmin (bool, optional): 是否为管理员. Defaults to False
        """
        point: str = "/sso/admin/user/login" if isAdmin else "/sso/user/login"
        payload: dict = {
            "account": account,
            "password": psd,
            "accountType": accountType
        }
        loginResponse: Response | None = apb.dou_request('post', point, json=payload)
        loginToken: str = loginResponse.get("value").get("token", "")
        # 如果是多个后台登录则根据不同情况进行拆分, 然后再分批写入local db中
        apb.set("DouGongLoginJwtToken", loginToken)
        print("pickledb get token:",  apb.get("DouGongLoginJwtToken"))
